package com.jvxb.demo.utils;

import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.http.HttpStatus;

/**
 * 响应数据
 *
 * @author jvxb
 */
@ApiModel("响应数据")
public class ResponseDataVo<T> implements Serializable {

    private static final long serialVersionUID = -4772210798944513134L;

    @ApiModelProperty("响应状态码")
    protected Integer code;

    @ApiModelProperty("响应消息")
    protected String message;

    @ApiModelProperty("响应数据")
    protected T data;

    public static <T> ResponseDataVo<T> success() {
        return success(null);
    }

    public static <T> ResponseDataVo<T> success(T result) {
        return new ResponseDataVo<T>().code(HttpStatus.OK.value()).result(result);
    }

    public static <T> ResponseDataVo<T> error(String message) {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), message);
    }

    public static <T> ResponseDataVo<T> error(int code, String message) {
        ResponseDataVo<T> msg = new ResponseDataVo<>();
        msg.setMessage(message);
        return msg.code(code);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public ResponseDataVo<T> code(int code) {
        this.code = code;
        return this;
    }

    public ResponseDataVo<T> result(T result) {
        this.data = result;
        return this;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}
